<?php

/**
 * information actions.
 *
 * @package    emc
 * @subpackage information
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class informationActions extends sfActions
{
	/**
	* Executes index action
	*
	* @param sfRequest $request A request object
	*/
	public function executeIndex(sfWebRequest $request)
	{
		$this->notify = $request->getParameter('notify', null);
		$this->information_form = new InformationForm();
		$q = Doctrine_Query::create()
			->select('o.*')
			->from('Information o')
			->addWhere('o.is_active = true');
		$this->informations = $q->fetchArray();
		return sfView::SUCCESS;
	}
	
	public function executeDelete(sfWebRequest $request)
	{
		$information_id = $request->getParameter('information_id', null);
		$information = Doctrine_Core::getTable('Information')->find($information_id);
		if ($information)
			$information->delete();
		$this->redirect('@information_list?notify=delete_information_success');
	}
	
	public function executeEdit(sfWebRequest $request)
	{
		$data = $request->getParameter('information', null);
		if ($data) {
			if ($data['information_id']) {
				$information = Doctrine_Core::getTable('Information')->find($data['information_id']);
				$notify = 'update';
			} else {
				$information = new Information();
				$notify = 'create';
			}
			$information->alias = $data['alias'];
			$information->content = $data['content'];
			$information->save();
		
			$this->redirect('@information?notify='.$notify.'_page_success');
		} else {
			$this->information_id = $request->getParameter('information_id', null);
			if ($this->information_id) {
				$information = Doctrine_Core::getTable('Information')->find($this->information_id);
				if ($information)
					$this->information_form = new InformationForm($information);
			} else
				$this->information_form = new InformationForm();
		}
		return sfView::SUCCESS;
	}
}
